#include "StdAfx.h"
#include "PhoneLight.h"

VAMPIRE_NAMESPACE_BEGIN

REGISTER_HELPER_IMPLEMENT(PhoneLight);

PhoneLight::PhoneLight(void)
{
	bindHandles();
	setToDefault();
}

void PhoneLight::bindHandles()
{
	mHandles.modelViewProj = mpData->GetParameterByName(NULL, "modelViewProj");
	mHandles.globalAmbient = mpData->GetParameterByName(NULL, "globalAmbient");
	mHandles.diffuseColor = mpData->GetParameterByName(NULL, "diffuseColor");
	mHandles.specularColor = mpData->GetParameterByName(NULL, "specularColor");
	mHandles.lightPos = mpData->GetParameterByName(NULL, "lightPos");
	mHandles.eyePos = mpData->GetParameterByName(NULL, "eyePos");
	mHandles.kEmissive = mpData->GetParameterByName(NULL, "kEmissive");
	mHandles.kAmbient = mpData->GetParameterByName(NULL, "kAmbient");
	mHandles.kDiffuse = mpData->GetParameterByName(NULL, "kDiffuse");
	mHandles.kSpecular = mpData->GetParameterByName(NULL, "kSpecular");
	mHandles.shininess = mpData->GetParameterByName(NULL, "shininess");
}

void PhoneLight::setToDefault()
{
	setDiffuseColor(ColorValue::WHITE);
	setSpecularColor(ColorValue::WHITE);
	setPosition(Vector3::UNIT_Y * 10);
}

void PhoneLight::setDiffuseColor( const ColorValue& color )
{
	mGlobals.diffuseColor = color;
	mpData->SetVector(mHandles.diffuseColor, &(mGlobals.diffuseColor.toVector4().mData));
}

void PhoneLight::setSpecularColor( const ColorValue& color )
{
	mGlobals.specularColor = color;
	mpData->SetVector(mHandles.specularColor, &(mGlobals.specularColor.toVector4().mData));
}

void PhoneLight::setPosition( const Vector3& pos )
{
	mGlobals.lightPos = pos;
	mpData->SetVector(mHandles.lightPos, (D3DXVECTOR4*)&(mGlobals.lightPos.mData));
}

void PhoneLight::setTransformMatrix( const Matrix44& mat )
{
	mVariables.modelViewProj = mat;
	mpData->SetMatrix(mHandles.modelViewProj, &(mat.mData));
}

void PhoneLight::setEyePosition( const Vector3& pos )
{
	mVariables.eyePos = pos;
	mpData->SetVector(mHandles.eyePos, (D3DXVECTOR4*)&(mVariables.eyePos.mData));
}

void PhoneLight::setEmissive( const ColorValue& k )
{
	mVariables.kEmissive = k;
	mpData->SetVector(mHandles.kEmissive, (D3DXVECTOR4*)&(mVariables.kEmissive.mData));
}

void PhoneLight::setAmbient( const ColorValue& k )
{
	mVariables.kAmbient = k;
	mpData->SetVector(mHandles.kAmbient, (D3DXVECTOR4*)&(mVariables.kAmbient.mData));
}

void PhoneLight::setDiffuse( const ColorValue& k )
{
	mVariables.kDiffuse = k;
	mpData->SetVector(mHandles.kDiffuse, (D3DXVECTOR4*)&(mVariables.kDiffuse.mData));
}

void PhoneLight::setSpecular( const ColorValue& k )
{
	mVariables.kSpecular = k;
	mpData->SetVector(mHandles.kSpecular, (D3DXVECTOR4*)&(mVariables.kSpecular.mData));
}

void PhoneLight::setShininess( Real s )
{
	mVariables.shininess = s;
	mpData->SetFloat(mHandles.shininess, s);
}

VAMPIRE_NAMESPACE_END